#clang --help | grep -i macro
#结果中有 -imacros

#llvm代码中搜索 :  -imacros
#结果中有 /pubx/llvm-project/clang/lib/Frontend/InitPreprocessor.cpp
#进一步找到 /pubx/llvm-project/clang/include/clang/Basic/MacroBuilder.h 中的 类MacroBuilder的函数defineMacro

#cd /pubx/llvm-project/analyze_clang_by_gdb; gdb   --args /pubx/llvm15-build/bin/clang    -c user_main.cpp -o user_main.o
#source macro_dev.gs
#or:
#cd /pubx/llvm-project/analyze_clang_by_gdb; gdb -x  macro_dev.gs  --args /pubx/llvm15-build/bin/clang    -c user_main.cpp -o user_main.o
#grep MAX_USER_ID macro_dev.log
#没找到 User.h 中的 宏名字 MAX_USER_ID

set logging file macro_dev.log
set logging on

set print pretty on
set pagination off

set follow-exec-mode new
set follow-fork-mode child


set breakpoint pending on

#载入 自定义gdb命令 Twine_union_Child_print:  打印单个宏名字或单个宏值
source Twine_union_Child_print.gs

break MacroBuilder::defineMacro
# 1       breakpoint     keep y   0x000055555d39a9d8 in clang::MacroBuilder::defineMacro(llvm::Twine const&, llvm::Twine const&) at /pubx/llvm-project/clang/include/clang/Basic/MacroBuilder.h:30
#断点1 处理过程 如下:
commands 1
#断点1 处理过程 开始
#停在断点1
silent 

printf "Name_address:0x%x, Value_address:0x%x \n",&Name, &Value

#打印宏名字和宏值
Twine_union_Child_print Name.LHS Name.LHSKind "Name.LHS"
Twine_union_Child_print Value.LHS Value.LHSKind  "Value.LHS"
Twine_union_Child_print Name.RHS Name.RHSKind "Name.RHS"
Twine_union_Child_print Value.RHS Value.RHSKind "Value.RHS"

if strcmp(Name.LHS.ptrAndLength.ptr,"__GCC_HAVE_DWARF2_CFI_ASM") == 0
	print "停下看看了"
else
	continue
end
#if结束

#继续运行被调试程序
continue

end
#断点1 处理过程 结束

#定义完以上内容, 现在可以启动被调试程序了:
run

#正常退出gdb
quit

